#include "../include/IMovableEntityBehaviour.h"
#include "../include/CDefaultShotBehaviour.h"

//**************************
//Description : Constructor
//Parameters : Value for m_iX, m_iY,
//              m_iSpeedX, m_iSpeedY,
//              m_iWidth, m_iHeight,
//              the ratio for the collision box
//              the type of colision
//              m_iLives
//Note : None
//**************************
IMovableEntityBehaviour::IMovableEntityBehaviour(int _iX, int _iY,
                                                int _iSpeedX, int _iSpeedY,
                                                int _iWidth, int _iHeight,
                                                float _fRatioW, float _fRatioH,
                                                TYPE_COLLISION _iTypeCollision,
                                                int _iLives)
    : IDefaultEntityBehaviour(_iX, _iY,
                            _iSpeedX, _iSpeedY,
                            _iWidth, _iHeight,
                            _fRatioW, _fRatioH,
                            _iTypeCollision),
    m_iCurrentNumLives(_iLives),
    m_iNumLives(_iLives)
{
    m_lLastPrimaryShoot = 0;
    m_lLastSecondaryShoot = 0;

    m_vShots = new std::list<CDefaultShotBehaviour *>();
}

//**************************
//Description : Copy Constructor
//Parameters : A IMovableEntityBehaviour
//Note : None
//**************************
IMovableEntityBehaviour::IMovableEntityBehaviour(IMovableEntityBehaviour & _MovableEntity)
    : IDefaultEntityBehaviour(_MovableEntity)
{
    if ( _MovableEntity.m_vShots != NULL )
        m_vShots = new std::list<CDefaultShotBehaviour *>(*_MovableEntity.m_vShots);
    else
        m_vShots = new std::list<CDefaultShotBehaviour *>();

    m_iNumLives = _MovableEntity.m_iNumLives;
    m_iCurrentNumLives = _MovableEntity.m_iCurrentNumLives;

	m_iPrimaryShot = _MovableEntity.m_iPrimaryShot;
	m_iSecondaryShot = _MovableEntity.m_iSecondaryShot;

    m_lLastPrimaryShoot = _MovableEntity.m_lLastPrimaryShoot;
    m_lLastSecondaryShoot = _MovableEntity.m_lLastSecondaryShoot;

    m_iTimeBetweenPrimaryShot = _MovableEntity.m_iTimeBetweenPrimaryShot;
    m_iTimeBetweenSecondaryShot = _MovableEntity.m_iTimeBetweenSecondaryShot;
}

//**************************
//Description : Destructor
//Parameters : None
//Note : None
//**************************
IMovableEntityBehaviour::~IMovableEntityBehaviour()
{
    delete m_vShots;
}

//**************************
//Description : Restore the current lives to the initial number
//Parameters : None
//Return Value : None
//Note : None
//**************************
void IMovableEntityBehaviour::RestoreLife()
{
    m_iCurrentNumLives = m_iNumLives;
}

//**************************
//Description : Return the current number of lives
//Parameters : None
//Return Value : The current number of lives
//Note : None
//**************************
int IMovableEntityBehaviour::HasLives() const
{
    return m_iCurrentNumLives;
}

//**************************
//Description : Give _iNumLives to m_iNumLives
//Parameters : The number of lives
//Return Value : None
//Note : None
//**************************
void IMovableEntityBehaviour::AddLife(int _iNumLives)
{
    m_iCurrentNumLives += _iNumLives;
}

//**************************
//Description : Decrease m_iNumLives of _iNumLives
//Parameters : None
//Return Value : None
//Note : None
//**************************
void IMovableEntityBehaviour::LoseLife(int _iNumLives)
{
    m_iCurrentNumLives -= _iNumLives;
}

//**************************
//Description : Return whether the entity is dead or not
//Parameters : None
//Return Value : True if _iLives == 0, otherwise false
//Note : None
//**************************
bool IMovableEntityBehaviour::IsDead() const
{
    return (m_iCurrentNumLives <= 0);
}

//**************************
//Description : Erase all the shots
//Parameters : None
//Return Value : None
//Note : None
//**************************
void IMovableEntityBehaviour::ClearShots()
{
    m_vShots->clear();
}

//**************************
//Description : Return the shots of the entity
//Parameters : None
//Return Value : shots of the entity or NULL if none
//Note : None
//**************************
std::list<CDefaultShotBehaviour *> * IMovableEntityBehaviour::HasShots()
{
    return m_vShots;
}

//**************************
//Description : A shot is out of the screen or collides with an entity, we pop it out
//Parameters : The shot to pop out of the list
//Return Value : The iterator after the pop
//Note : None
//**************************
std::list<CDefaultShotBehaviour *>::iterator IMovableEntityBehaviour::PopShot(std::list<CDefaultShotBehaviour *>::iterator _Shot)
{
    return m_vShots->erase(_Shot);
}

//**************************
//Description : Pop out of the list all shots that are not in the screen anymore
//Parameters : None
//Return Value : None
//Note : None
//**************************
void IMovableEntityBehaviour::PopShotOutOfScreen()
{
    m_vShots->remove_if(IDefaultEntityBehaviour::EntityOutOfScreen);
}
